package com.example.quartz.basic;

import org.quartz.*;

import java.util.Date;
//@DisallowConcurrentExecution  -禁止并发执行，防止多线程执行
//@PersistJobDataAfterExecution持久化数据，对triggerdatamap无效
@DisallowConcurrentExecution
@PersistJobDataAfterExecution
public class MyJob implements Job {
    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        System.out.println("Myjob execute-------->"+new Date());

        JobDataMap Jobdetail = jobExecutionContext.getJobDetail().getJobDataMap();
        JobDataMap trigger = jobExecutionContext.getTrigger().getJobDataMap();

//        jobDataMap = Jobdetail+trigger
        JobDataMap jobDataMap = jobExecutionContext.getMergedJobDataMap();
        System.out.println("Jobdetail:"+Jobdetail.get("name"));
        System.out.println("trigger:"+trigger.get("year"));
        System.out.println("merge:"+trigger.get("year"));
        System.out.println("=======================>");

        //持久化
        Jobdetail.put("count",Jobdetail.getInt("count")+1);
        trigger.put("count1",trigger.getInt("count1")+1);
        System.out.println(Jobdetail.getInt("count"));
        System.out.println(trigger.getInt("count1"));
    }
}
